package com.tt.dao;

import java.util.List;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.stereotype.Repository;

import com.tt.entity.Food;
import com.tt.entity.Hotel;

@Repository

public class HotelDaoImpl {
	
	@Resource
	private SessionFactory sessionFactory;
	
	//��ѯ����ס����Ϣ
	public List<Hotel>  hotelfoundAll(){
		 String hql ="from Hotel";
		 Query query = this.sessionFactory.getCurrentSession().createQuery(hql);
		 List<Hotel> Hlist = query.list();
		 return Hlist;
	}
	
	//���ס��
	public int  addHotel(Hotel hotel){
		int addHotel=(int) this.sessionFactory.getCurrentSession().save(hotel);
		return 1;
	}
	
	//ɾ��ס����Ϣ
	public  void  deteleHotel(Integer id){
//		String hql="detele Hotel where id=?";
//		Query query = this.sessionFactory.getCurrentSession().createQuery(hql);
//		query.setParameter(0,id);
//		Hotel detehotel=(Hotel) query.uniqueResult();
//		this.sessionFactory.getCurrentSession().delete(detehotel);
		 Session session = this.sessionFactory.getCurrentSession();
		   Hotel hotel = session.get(Hotel.class, id);
		   System.out.println(hotel+"���Ҷ���");
		   session.delete(hotel);
		   System.out.println(hotel+"���Ҷ���2222"); 
	}
	//�޸�ס����Ϣ
	public  void updateHotel(Hotel hotel){
		this.sessionFactory.getCurrentSession().update(hotel);	
	}
	
	//�޸�ͼƬ
   public String  updatephoto(Integer id){
	   
	   Query query=this.sessionFactory.getCurrentSession().createQuery("select img from Hotel where id=?");
	     //���ò���(�󶨲���)������ռλ����ֵ����ΪHQL�����ʺ���ռλ��  
		query.setParameter(0, id);
		String listimg = (String) query.uniqueResult();
		return listimg;
   }
	
	//id ����
	public Hotel showHotel(Integer id){
		String hql ="from Hotel where id=?";
		   Query query = this.sessionFactory.getCurrentSession().createQuery(hql);
		   query.setParameter(0, id);
		   Hotel hid = (Hotel) query.uniqueResult();
		   return hid;
	}
	
	public Hotel showHotelsingle(Integer id){
		
		String hql ="from Hotel where id=?";
		   Query query = this.sessionFactory.getCurrentSession().createQuery(hql);
		   query.setParameter(0, id);
		   Hotel hid = (Hotel) query.uniqueResult();
		   return hid;
	}
}
